"""
配置管理类
包含应用的所有配置信息
"""

import os
import stripe


class Config:
    """应用配置类"""
    
    # Stripe配置
    STRIPE_API_KEY = "sk_test_51Ogsw5B0IyqaSJBrwczlr820jnmvA1qQQGoLZ2XxOsIzikpmXo4pRLjw4XVMTEBR8DdVTYySiAv1XX53Zv5xqynF00GfMqttFd"
    
    # 数据存储配置
    DATA_DIR = "data"
    CUSTOMERS_FILE = os.path.join(DATA_DIR, "customers.json")
    PRODUCTS_FILE = os.path.join(DATA_DIR, "products.json")
    SUBSCRIPTIONS_FILE = os.path.join(DATA_DIR, "subscriptions.json")
    
    # 应用配置
    APP_HOST = "0.0.0.0"
    APP_PORT = 8003
    
    # 默认URL配置
    DEFAULT_SUCCESS_URL = "http://localhost:8003/subscription/success?session_id={CHECKOUT_SESSION_ID}"
    DEFAULT_CANCEL_URL = "http://localhost:8003/subscription/cancel"
    DEFAULT_PORTAL_RETURN_URL = "http://localhost:8003/portal-return"
    
    # Webhook配置
    WEBHOOK_ENDPOINT_SECRET = "whsec_rWUYosj1unnCedx4MMY3fxliTTzZl1Vu"  # 请替换为您的webhook密钥
    WEBHOOK_URL = "http://localhost:8003/webhook"
    
    @classmethod
    def initialize(cls):
        """初始化配置"""
        # 设置Stripe API密钥
        stripe.api_key = cls.STRIPE_API_KEY
        
        # 确保数据目录存在
        os.makedirs(cls.DATA_DIR, exist_ok=True)
        
        print(f"配置初始化完成")
        print(f"数据目录: {cls.DATA_DIR}")
        print(f"应用地址: {cls.APP_HOST}:{cls.APP_PORT}")
